#pragma once

#include <sstream>

#include "common/types.h"
#include "common/lf_queue.h"

using namespace Common;

namespace Exchange {
#pragma pack(push, 1) // 确保这些结构体紧凑无填充。这很重要，因为它们在后续章节会作为扁平二进制结构在网络上传输。
  enum class ClientRequestType : uint8_t { // 用于标识订单请求的类型（新订单或撤单）
    INVALID = 0,
    NEW = 1,
    CANCEL = 2
  };

  inline std::string clientRequestTypeToString(ClientRequestType type) {
    switch (type) {
      case ClientRequestType::NEW:
        return "NEW";
      case ClientRequestType::CANCEL:
        return "CANCEL";
      case ClientRequestType::INVALID:
        return "INVALID";
    }
    return "UNKNOWN";
  }

  struct MEClientRequest {
    ClientRequestType type_ = ClientRequestType::INVALID; // 请求类型

    ClientId client_id_ = ClientId_INVALID; // 请求所属客户端
    TickerId ticker_id_ = TickerId_INVALID; // 目标交易标的
    OrderId order_id_ = OrderId_INVALID; // 相关订单 ID（新单或已有订单标识）

    Side side_ = Side::INVALID; // 订单方向
    Price price_ = Price_INVALID; // 订单价格
    Qty qty_ = Qty_INVALID; // 订单数量

    auto toString() const {
      std::stringstream ss;
      ss << "MEClientRequest"
         << " ["
         << "type:" << clientRequestTypeToString(type_)
         << " client:" << clientIdToString(client_id_)
         << " ticker:" << tickerIdToString(ticker_id_)
         << " oid:" << orderIdToString(order_id_)
         << " side:" << sideToString(side_)
         << " qty:" << qtyToString(qty_)
         << " price:" << priceToString(price_)
         << "]";
      return ss.str();
    }
  };

#pragma pack(pop)

  typedef LFQueue<MEClientRequest> ClientRequestLFQueue;
}
